'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	await db.collection('rx-users').where({ _id: event.userId }).update({ name: event.name, mobile: event.mobile })
	
	// 用户与类型与诊所关联
	const res_users_clinic = await db.collection('rx-users-clinic').where({ userId: event.userId, types: event.types }).get()
	const clinic_list = res_users_clinic.data[0].clinic
	clinic_list.push(event.clinicId)
	await db.collection('rx-users-clinic').doc(res_users_clinic.data[0]._id).update({ clinic: clinic_list })
	
	const res_data = await db.collection('rx-clinic').doc(event.clinicId).get()
	
	//返回数据给客户端
	return { data: res_data.data[0], code: 200, msg: 'ok.' }
};
